//
// Created on 2024/3/28.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef OH_WEB_RTC_OHOS_HARDWARE_VIDEO_ENCODER_H
#define OH_WEB_RTC_OHOS_HARDWARE_VIDEO_ENCODER_H

#include "api/video_codecs/video_encoder.h"
#include "media/base/codec.h"
#include "modules/video_coding/codecs/h264/include/h264.h"
#include "ohos_common.h"
#include "ohos_video_encoder.h"
#include <bits/alltypes.h>
#include <thread>
#include <multimedia/player_framework/native_avmemory.h>
#include "ohos_video_common.h"
#include <src/codec/api/wels/codec_api.h>
namespace webrtc{
namespace ohos{

class OhosHardwareVideoEncoder : public H264Encoder {
public:
    OhosHardwareVideoEncoder(const cricket::VideoCodec& codec);
    ~OhosHardwareVideoEncoder();
    int32_t InitEncode(const VideoCodec *codec_settings, int32_t number_of_cores, size_t max_payload_size) override;
    int InitEncode(const VideoCodec *codec_settings, const VideoEncoder::Settings &settings)override;
    int32_t RegisterEncodeCompleteCallback(EncodedImageCallback *callback) override ; 
    int32_t Encode(const VideoFrame& frame, const std::vector<VideoFrameType>* frame_types)override ;
    void SetRates(const RateControlParameters &parameters) override;  
    int32_t Release()override;
    EncoderInfo GetEncoderInfo()const override;
    static std::unique_ptr<OhosHardwareVideoEncoder> Create(const cricket::VideoCodec &codec);
    static std::unique_ptr<OhosHardwareVideoEncoder> Create();

private:
    void OutputThread();
    std::unique_ptr<OhosVideoEncoder> encoder_;
    std::unique_ptr<std::thread> outputThread_;
    int64_t nextPTS_ { 0 };
    double fps_ { 0 };
    EncodedImageCallback* encoded_image_callback_ { nullptr };
    std::vector<ISVCEncoder*> encoders_;
    CodecData codecData_;
    FormatInfo formatInfo_;
    
    uint32_t width_ = 0;
    uint32_t height_ = 0;
    uint32_t timestamp_ = 0;
    absl::optional<webrtc::ColorSpace> colorSpace_;
};
}
}
#endif //OH_WEB_RTC_OHOS_HARDWARE_VIDEO_ENCODER_H
